package org.gitman.agentplatform.core.services;

import java.util.Collection;
import java.util.LinkedList;

import org.gitman.agentplatform.agent.api.Agent;
import org.gitman.agentplatform.agent.api.AgentFactory;
import org.gitman.agentplatform.core.exceptions.BadArgsException;

public class AgentFactoryRegistrationService {
	private Collection<AgentFactory> factories;
	
	
	public AgentFactoryRegistrationService(){
		factories = new LinkedList<AgentFactory>();
	}
	
	public void addFactory(AgentFactory factory) throws BadArgsException{
		if(factory != null){
			for(Class<? extends Agent> clazz : factory.getAvailableAgents().keySet()){
				for(AgentFactory f : factories){
					if(f.getAvailableAgents().keySet().contains(clazz)){
						throw new BadArgsException("Factory of Agent class: " + clazz.getCanonicalName() + " is alread registred");
					}
				}
			}
			factories.add(factory);
		}
	}
	
	public Collection<AgentFactory> getAgentFactories(){
		return factories;
	}
	
	
}
